#ifndef QIK_H
#define QIK_H

#include "Image.h"
#include "DoubleMatrix.h"
#include "ByteStream.h"

#include <fstream>

class Qik: public Image
{
public:
	Qik(bool isstripped = false);
	Qik(unsigned int newWidth, unsigned int newHeight);
	~Qik();

	virtual void ReadFromFile(const char* filename);
	virtual void WriteToFile(const char* filename);

	void StartLogging(const char *filename);
	void StopLogging();
	bool Logging() const;
	void EnableWriteback();

	void SetCompressionFactor(double factor);
	void ReadFromStream(ByteStream& stream);
	void WriteToStream(ByteStream& stream);

protected:

private:
	std::ofstream *logfile;
	double compressionFactor;
	bool stripped;
	bool encodewriteback;

	static const unsigned int BLOCKW = 4, BLOCKH = 4;
	static const char *VERSIONHEADER;
	static const double defaultCompressionFactor;
	static DoubleMatrix defaultQuantizationTable;


	std::ofstream& Log();
	void ReadHeaderFromStream(ByteStream& stream);
	void WriteHeaderToStream(ByteStream& stream);
	void DecodeMatrix(DoubleMatrix& Y, const DoubleMatrix& quantizationTable, bool sublogging);
	void EncodeMatrix(DoubleMatrix& X, const DoubleMatrix& quantizationTable, bool sublogging);
};

#endif //QIK_H
